-- Priest
-- Created by chengb Aug/4/2016
-- 神官

-- 贤者冈布奥的编号
local PRIEST_PET_ID = 49;

-- 初始化
function initPriest(self)
    self.item:removeAllChildren();

    local class = self.gridData.class;
    local buildingInfo = BuildingBonusM.queryBuildingView(class);

    if not buildingInfo then
        error("获取不到建筑查看配置，元素类型：" .. class);
        return;
    end

    local iconPath = getHeroIconPath(PRIEST_PET_ID);

    local function onClicked(sender, eventType)
        if eventType == ccui.TouchEventType.began then
            if self.gridData.state == GRID_STATE_DISABLE then
                -- 已经失效，不处理
                return;
            end

            -- 巨坑已被埋葬，神官消失
            if not DungeonM.isGridExist(GRID_TYPE_HUGE_HOLE) and not DungeonM.isGridExist(GRID_TYPE_MONSTER_BUILDING) then
                if DungeonActionM.go("priest_disappear", self.gridData:getPos()) then
                    local alertList = splitString(getLocStr("priest_disappear_tip"), "\n");
                    splitAlert(alertList);
                    playBuildingDisappear(self);
                end
                return;
            end

            AudioM.playFx("ui_open1");
            self:openBuildingView(nil, nil, nil, nil, nil, iconPath);
        end
    end

    self.icon = ccui.ImageView:create(iconPath);
    self.icon:setTouchEnabled(true);
    self.icon:addTouchEventListener(onClicked);
    self.item:addChild(self.icon);
    self.icon:setVisible(true);
    self.icon:setScale(1.2);
    self.icon:setPositionY(-10);

    -- 呼吸
    self.needAnimation = true;
end
